<template>
    <div>
        <div class="filter-container">
            <el-input @keyup.enter.native="handleFilter" :clearable="true" style="width: 200px;" class="filter-item" placeholder="商品名称" v-model="listQuery.productName">
            </el-input>
            <span class="tip">商品分类:</span>
            <el-select v-model="listQuery.tradeType" placeholder="请选择商品分类">
              <el-option :label="item.tradeTypeName" :value="item.tradeType" v-for="(item,index) in GoodsTradeTypeList" :key="index"></el-option>
            
          </el-select>
            <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查询</el-button>
        </div>
        <el-table :data="list" border fit highlight-current-row style="width:100%">
           
            <el-table-column align="center" label="商品名称">
                <template slot-scope="scope">
                <span class="text">{{scope.row.productName}}</span>
                </template>
            </el-table-column>
             <el-table-column align="center" label="持有总量">
                <template slot-scope="scope">
                <span class="text">{{scope.row.cysl}}</span>
                </template>
            </el-table-column>
             <el-table-column align="center" label="可用数量">
                <template slot-scope="scope">
                <span class="text">{{scope.row.kysl}}</span>
                </template>
            </el-table-column>

             <el-table-column align="center" label="持有均价/元">
                <template slot-scope="scope">
                <span class="text">{{scope.row.cyjj}}</span>
                </template>
            </el-table-column>
             <el-table-column align="center" label="浮动盈亏/元">
                <template slot-scope="scope">
                <span class="text">{{scope.row.fdky}}</span>
                </template>
            </el-table-column>
             <el-table-column align="center" label="占用资金/元">
                <template slot-scope="scope">
                <span class="text">{{scope.row.zyzj}}</span>
                </template>
            </el-table-column>
            <el-table-column
            prop="tradeTypeName"
            label="商品分类"
           >
          
          </el-table-column>
        </el-table>
         <div class="pagination-container">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.currentPage" :page-sizes="[5,10,20,30,40]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
export default {
  data() {
    return {
      Visible: false,
      Visibleadd: false,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        currentPage: 1,
        pageSize: 10,
        productName: undefined,
        tradeType:''
      },
      sid: '',
      formLabelWidth: '120px',
      form: {
        id: '',
        tactfulDic: ''
      },
      form2: {
        tactfulDic: ''
      },
      GoodsTradeTypeList:[]
    }
  },
  created() {
    this.getList();
    this.getGoodsTradeTypeList()
  },
  methods: {
       tradeType(id){
      let params = '';
      switch(id){
        case 1:
        params = '活期交易商品';
        break;
        case 2:
        params = '定期交易商品';
        break;
        default:

      }
      return params
    },
    async getGoodsTradeTypeList(){
            let {data} = await this.$post({
                api:'/api/goods/getGoodsTradeTypeList',
                
            })
            if(data.code === 0){
                this.GoodsTradeTypeList = data.data
                console.log(data)
            }
    },
    getList() {
      var that = this
      that.$post({
            api: "/tran/holdManage",
            data: {
                userId: JSON.parse(localStorage.getItem("userInfo")).userId,
               ...that.listQuery
            }

        }).then(({ data }) => {
        if(data.code === 0){
            that.list = data.data.list
            that.total = data.data.total
        }
        console.log("holdManage",data)
        });
    },
    handleFilter() {
      this.listQuery.currentPage = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.currentPage = val
      this.getList()
    },
  }
}
</script>